import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { SendoutDtl } from '../sendoutdetail/sendoutdetail.component';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-sod',
  templateUrl: './sod.component.html',
  styleUrls: ['./sod.component.css']
})
export class SodComponent implements OnInit {

  url:string = "http://www.xdfznh.club/sod/go";
  billCode:string = "F190714027";// 发货单据编号
  dataSet:SendoutDtl[] = [];

  billDate:string = "";//bill_date - 发货日期
  clientName:string = "";//client_material - 客户名称

  printed:string = "";

  constructor(
    private http:HttpClient,
    private route:ActivatedRoute
  ) { 
    // this.billCode = this.route.snapshot.queryParams["billCode"];// 从地址栏重获取参数 - 单据编号
    this.getDetails();
  }

  ngOnInit() {
  }

  getDetails(){
    if(!this.billCode) return
    if(this.billCode.length<=0) return

    let reqUrl = this.url + '/' + this.billCode;
    console.log("获取发货明细数据的请求是：" + reqUrl);
    
    this.http.get<SendoutDtl[]>(reqUrl).subscribe(
      (res:SendoutDtl[]) =>{
        this.dataSet = res;
        this.clientName = res[0].client_material;
        
        console.log("请求获取发货单明细数据成功！");
        console.log(res);
        this.printed = res[0].bill_code + ',' + res[0].client_id + ',' + res[0].orderno;
      },error => console.log("请求指定发货单明细数据时出错！")
      
    )
  }
}
